package com.chenchao.designer.agency;
/**
 * @encoding : UTF-8
 * @Time : 2020/11/17 15:47
 * @Author : Chen Chao
 * @File : javaSE.com.chenchao.javadesigner.agency.Agency.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 * 代理模式
 * 代理对象与被代理对象要实现同一个接口
 */
public class Agency {
    public static void main(String[] args) {
        new TakeTester(new Student("王二麻子")).signOneSName();
    }
}
interface exam{
    void signOneSName();
}

/**
 * 被代理对象
 */
class Student implements exam{
    String name;

    public Student(String name) {
        this.name = name;
    }

    @Override
    public void signOneSName() {
        System.out.println("我叫"+this.name);
    }
}

/**
 * 代理对象
 */
class TakeTester implements exam{
    private Student student;

    public TakeTester(Student student) {
        this.student = student;
    }

    @Override
    public void signOneSName() {
        getMoney();
        this.student.signOneSName();
        returnMoney();
    }

    private void returnMoney() {
        System.out.println("本代考从不退钱");
    }

    private void getMoney() {
        System.out.println("本代考200元一次，包不过");
    }
}